package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏西西
 * Date: 2023-08-29
 * Time: 16:42
 */
public class ThreadD12 {
    public static void main(String[] args) {
        //serial();
        currency();
    }

    public static void serial(){
        long beg = System.currentTimeMillis();
        long a = 0;
        for (long i = 0; i <1000_000_000L ; i++) {
            a++;
        }
        long b = 0;
        for (long i = 0; i <1000_000_000L ; i++) {
            b++;
        }
        long end = System.currentTimeMillis();
        System.out.println("执行时间" + (end - beg) +"ms");
    }

    public static void currency(){
        Thread t1 = new Thread(() -> {
            long a = 0;
            for (long i = 0; i < 1000_000_000L ; i++) {
                a++;
            }
        });

        Thread t2 = new Thread(() -> {
            long b = 0;
            for (long i = 0; i < 1000_000_000L ; i++) {
                b++;
            }
        });
        long beg2 = System.currentTimeMillis();
        t1.start();
        t2.start();

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        long end2 = System.currentTimeMillis();

        System.out.println("并发时间" +(end2 - beg2) +"ms");
    }

}
